package com.android.klmgreendao;

import android.app.Application;

import com.android.klm.DaoMaster;
import com.android.klm.DaoSession;

import org.greenrobot.greendao.database.Database;

/**
 * Created by klm_android on 2017/7/3.
 */

public class KlmApplication extends Application {
    public static final String DATABASE_NAME = "my-db-name";

    private DaoSession daoSession;

    public static KlmApplication instances;
    @Override
    public void onCreate() {
        super.onCreate();
        instances = this;
        initDao();
    }

    public static KlmApplication getInstances(){
        if (instances == null) {
            instances = new KlmApplication();
        }
        return instances;
    }

    public void initDao() {
        DaoMaster.DevOpenHelper openHelper = new DaoMaster.DevOpenHelper(this, DATABASE_NAME);
        Database db = openHelper.getWritableDb();
        daoSession = new DaoMaster(db).newSession();
    }

    public DaoSession getDaoSession() {
        return daoSession;
    }

}
